package com.ak.demo.myjob;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自定义业务
 */
@PersistJobDataAfterExecution
public class HelloJobPersist implements Job {
    private Integer count=0;

    public void setCount(Integer count) {
        this.count = count;
    }

    /**
     * 虽说每次都是创建新的，但是其中的 jobDataMap都一直延续了下去
     * @param context
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
          this.count=(Integer) context.getJobDetail().getJobDataMap().get("count");
          count++;
          System.out.println(count);
          context.getJobDetail().getJobDataMap().put("count",count);
    }

}